package com.yx.selector;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TestActivity extends AppCompatActivity {

    private TextView one;
    private List<TxlDataBean> datas = new ArrayList<>();//城市集合

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        TxlDataBean bean = new TxlDataBean();
        bean.setId("1");
        bean.setName("98K");//数字开头，会默认放入#号队
        datas.add(bean);
        bean = new TxlDataBean();
        bean.setId("2");
        bean.setName("M416");//字母开头
        datas.add(bean);
        bean = new TxlDataBean();
        bean.setId("3");
        bean.setName("广州");//文字开头
        datas.add(bean);
        bean = new TxlDataBean();
        bean.setId("4");
        bean.setName("$1289");//特殊字符开头，会默认放入#号队
        datas.add(bean);

        one = (TextView) findViewById(R.id.one);
        one.setOnClickListener(view -> {
            Intent in = new Intent(this, SelectorActivity.class);
            in.putExtra("yx_title", "请选择");//标题：请选择
            in.putExtra("yx_roo", (Serializable) datas);//Data集合List<String>
            startActivityForResult(in, 6);
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (resultCode) {
            case 6:
                //选择的城市
                String selectMy = data.getStringExtra("rooValue");
                if (selectMy != null && !"".equals(selectMy)) {
                    one.setText(selectMy);
                } else {
                    one.setText("什么也没选");
                }
                break;
        }

    }
}
